//
//  XMGTopics.m
//  BuDeJie
//
//  Created by 陈恒均 on 2018/1/31.
//  Copyright © 2018年 小码哥. All rights reserved.
//

#import "XMGTopics.h"

@implementation XMGTopics

-(CGFloat)cellHeight
{
    if (_cellHeight) return _cellHeight;

    _cellHeight += 55;
    CGSize textMaxSize = CGSizeMake(XMGScreenW - 2 * XMGMarin, MAXFLOAT);
    
//    _cellHeight += [self.text sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:textMaxSize].height + XMGMarin;
    
    _cellHeight += [self.text boundingRectWithSize:textMaxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil].size.height +XMGMarin;
    
    //中间内容
    if (self.type != XMGTopicTypeWord) {
        CGFloat middleW = textMaxSize.width;
        CGFloat middleH = middleW * self.height / self.width;
        
        if (middleH >= XMGScreenH) {
            middleH = 200;
            self.bigPicture = YES;
        }
        CGFloat middleY = _cellHeight;
        CGFloat middleX = XMGMarin;
        
        self.middleFrame = CGRectMake(middleX, middleY, middleW, middleH);
        
        _cellHeight += middleH + XMGMarin;

    }
    if (self.top_cmt.count) {
        _cellHeight += 18;
        NSDictionary *cmt = self.top_cmt.firstObject;
        NSString *content = cmt[@"content"];
        if (content.length == 0) {
            content = @"[语音评论]";
        }
        NSString *username = cmt[@"user"][@"username"];
        NSString *cmtText = [NSString stringWithFormat:@"%@ : %@", username, content];
        _cellHeight += [cmtText boundingRectWithSize:textMaxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16]} context:nil].size.height + XMGMarin;
    }
    
    _cellHeight += 35 +XMGMarin;
    
    return _cellHeight;
}

@end
